from itertools import (
    product,
    combinations_with_replacement,
    combinations,
    permutations,
    accumulate,
)


def test():
    smm()


# 笛卡尔积-------------------------------------------------------------------------------
def for3():
    for i in range(1, 100):
        for j in range(1, 100):
            for k in range(1, 100):
                if i * i + j * j == k * k:
                    print(i, j, k)


def for_product():
    # 笛卡尔积
    # for k in product("ABC", "xy"):
    #     print(k)

    for i, j, k in product(range(1, 100), repeat=3):
        if i * i + j * j == k * k:
            print(i, j, k)


# 元素可以重复的组合--------------------------------------------------------------------
def for31():
    for i in range(1, 100):
        for j in range(i, 100):
            for k in range(j, 100):
                if i * i + j * j == k * k:
                    print(i, j, k)


def for_cwr():
    # 元素可以重复的组合
    # for k in combinations_with_replacement("01", 3):
    #     print(k)
    for i, j, k in combinations_with_replacement(range(1, 100), 3):
        if i * i + j * j == k * k:
            print(i, j, k)


# 元素不可以重复的组合-----------------------------------------------------------------------
"""
砝码称不出的重量
- 有10个砝码
- 任意取3个，在[a,b]重量区间，哪些重量无法覆盖
"""


def weight():
    wlist = [5, 2, 3, 6, 5, 5, 6, 9, 12, 10]
    n = len(wlist)
    a, b = 10, 30
    wset = set(range(a, b + 1))
    for i in range(1, n):
        for j in range(i + 1, n):
            for k in range(j + 1, n):
                total = wlist[i] + wlist[j] + wlist[k]
                if total in wset:
                    wset.remove(total)
    print(wset)


def weight1():
    wlist = [5, 2, 3, 6, 5, 5, 6, 9, 12, 10]
    n = len(wlist)
    a, b = 10, 30
    wset = set(range(a, b + 1))
    for wi, wj, wk in combinations(wlist, 3):
        total = wi + wj + wk
        if total in wset:
            wset.remove(total)
    print(wset)


# 排列---------------------------------------------------------------
"""
PUZZLE: 1 LETTER = 1 UNIQUE DIGIT
    SEND
   +MORE
   -----
   MONEY
"""


def smm():
    for s, e, n, d, m, o, r, y in permutations(range(10), 8):
        if (
            s * 1000 + e * 100 + n * 10 + d + m * 1000 + o * 100 + r * 10 + e
            == m * 10000 + o * 1000 + n * 100 + e * 10 + y
            and m > 0
        ):
            # print(
            #     s * 1000 + e * 100 + n * 10 + d,
            #     "+",
            #     m * 1000 + o * 100 + r * 10 + e,
            #     "=",
            #     m * 10000 + o * 1000 + n * 100 + e * 10 + y,
            # )
            print(f" {s}{e}{n}{d}")
            print(f"+{m}{o}{r}{e}")
            print("-" * 6)
            print(f"{m}{o}{n}{e}{y}")

            print(f"{s=},{e=},{n=},{d=},{m=},{o=},{r=},{y=}")
